package com.netease.xone.activity;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.view.View;

import com.netease.xone.R;
import com.netease.xone.fragment.FragmentFindFriends;
import com.netease.xone.fragment.FragmentFindFriends.FindFrindsType;
import com.netease.xone.view.CustomViewPager;
import com.netease.xone.widget.tabview.AbsTabView.OnTabSelectListener;
import com.netease.xone.widget.tabview.FindFriendsTab;

public class ActivityFindFriends extends ActivityX1Base {

    public static void startActivity(Context context){
        Intent i = new Intent(context, ActivityFindFriends.class);
        context.startActivity(i);
    }


    private CustomViewPager mPager;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setTitle(R.string.find_friends);
        setContentView(R.layout.activity_find_friends);
        mPager = (CustomViewPager)findViewById(R.id.view_pager);
        mPager.setAllowedScrolling(false);
        FindFriendsPagerAdapter adapter = new FindFriendsPagerAdapter(getSupportFragmentManager());
        mPager.setAdapter(adapter);
        FindFriendsTab tab = (FindFriendsTab)findViewById(R.id.find_friend_tab);
        tab.setOnTabSelectListener(new OnTabSelectListener() {

            @Override
            public void onTabSelected(View tabView, int index) {
                mPager.setCurrentItem(index);
            }

            @Override
            public void onTabReSelected(View tabView, int index) {

            }
        });
    }

    private class FindFriendsPagerAdapter extends FragmentPagerAdapter {

        public FindFriendsPagerAdapter(FragmentManager fm) {
            super(fm);
        }

        @Override
        public Fragment getItem(int index) {
            switch(index){
                case 0:
                    return FragmentFindFriends.newInstance(FindFrindsType.guess_you_like);
                case 1:
                    return FragmentFindFriends.newInstance(FindFrindsType.popularity_list);
            }
            return null;
        }

        @Override
        public int getCount() {
            return 2;
        }

    };

}
